package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;

/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 2553 【排序】2024E磁盘容量
 * @version: 1.0
 */
import java.util.Arrays;
import java.util.Scanner;
public class E_2024E_2553__排序磁盘容量 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();

			String[] capacitys = new String[n];
			for (int i = 0; i < n; i++) capacitys[i] = sc.next();

			getResult(capacitys);
		}

		public static void getResult(String[] capacitys) {
			Arrays.sort(capacitys, (a, b) -> Long.compare(calc(a), calc(b)));
			for (String capacity : capacitys) {
				System.out.println(capacity);
			}
		}

		public static Long calc(String capacity) {
			long ans = 0;

			StringBuilder num = new StringBuilder();
			for (int i = 0; i < capacity.length(); i++) {
				char c = capacity.charAt(i);

				if (c >= '0' && c <= '9') {
					num.append(c);
				} else {
					switch (c) {
						case 'M':
							ans += Long.parseLong(num.toString());
							break;
						case 'G':
							ans += Long.parseLong(num.toString()) * 1024;
							break;
						case 'T':
							ans += Long.parseLong(num.toString()) * 1024 * 1024;
							break;
					}

					num = new StringBuilder();
				}
			}

			return ans;
		}
	}